package de.gratnik.sensors;

import java.util.List;

import android.app.Activity;
import android.net.wifi.WifiConfiguration;
import android.net.wifi.WifiManager;
import android.text.format.Formatter;
import android.util.Log;

public class WiFiComunicator {
	
	private static final String TAG = "WiFiComunicator";
	
	Activity activity = null;
	
	public WiFiComunicator(Activity activity) {
		this.activity = activity;
		
		String ip = getIP();
		Log.i(TAG, ip);
		
	}
	
	
	private String getIP() {
		WifiManager wim= (WifiManager) activity.getSystemService(activity.WIFI_SERVICE)  ;

		List<WifiConfiguration> l=  wim.getConfiguredNetworks(); 
		if (l.size() > 0) {
		    WifiConfiguration wc=l.get(0); 

		   return Formatter.formatIpAddress(wim.getConnectionInfo().getIpAddress()); }
		return "127.0.0.1";
	}
}
